namespace PickGold.Charting
{
    using System;
    using System.ComponentModel;
    using System.Globalization;

    internal class AxisMinMaxValueConverter : DoubleConverter
    {
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            object obj2 = null;
            DateTime time;
            bool flag = false;
            string s = value as string;
            if (((context != null) && (context.Instance != null)) && (context.Instance is Axis))
            {
                Axis instance = (Axis) context.Instance;
                if (s != null)
                {
                    if (instance.InternalIntervalType == DateTimeIntervalType.Auto)
                    {
                        if (((instance.GetAxisValuesType() == ChartValueType.DateTime) || (instance.GetAxisValuesType() == ChartValueType.Date)) || ((instance.GetAxisValuesType() == ChartValueType.Time) || (instance.GetAxisValuesType() == ChartValueType.DateTimeOffset)))
                        {
                            flag = true;
                        }
                    }
                    else if (instance.InternalIntervalType != DateTimeIntervalType.Number)
                    {
                        flag = true;
                    }
                }
            }
            try
            {
                obj2 = base.ConvertFrom(context, culture, value);
            }
            catch (ArgumentException)
            {
                obj2 = null;
            }
            catch (NotSupportedException)
            {
                obj2 = null;
            }
            if (((s != null) && (flag || (obj2 == null))) && DateTime.TryParse(s, CultureInfo.CurrentCulture, DateTimeStyles.None, out time))
            {
                return time.ToOADate();
            }
            return base.ConvertFrom(context, culture, value);
        }

        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (((context != null) && (context.Instance != null)) && (context.Instance is Axis))
            {
                Axis instance = (Axis) context.Instance;
                if (destinationType == typeof(string))
                {
                    string str = DoubleDateNanValueConverter.ConvertDateTimeToString((double) value, instance.GetAxisValuesType(), instance.InternalIntervalType);
                    if (str != null)
                    {
                        return str;
                    }
                }
            }
            return base.ConvertTo(context, culture, value, destinationType);
        }
    }
}

